<script setup lang="ts">
import { storeToRefs } from 'pinia'
import { useUserStore } from '@/store/user'

defineProps<{ msg: string }>()

const router = useRouter()
const userStore = useUserStore()
const { age } = storeToRefs(userStore)

const onFuncClick = () => {
  userStore.$patch((state) => {
    state.firsrname = '李'
  })
  age.value = 23
  userStore.updateName('五')
}

const onRoutePush = () => {
  router.push({
    path: 'use',
  })
}
</script>

<template>
  <h1>{{ msg }}</h1>
  <div>{{ userStore.getFullNam }}</div>
  <div>{{ age }}</div>
  <button type="button" @click="onFuncClick">change: {{ age }}</button>
  <button @click="onRoutePush">跳转</button>
</template>

<style lang="scss" scoped>
a {
  color: #42b983;
}

label {
  margin: 0 0.5em;
  font-weight: bold;
}

code {
  background-color: #eee;
  padding: 2px 4px;
  border-radius: 4px;
  color: #304455;
}
</style>
